package com.znow.admin.system.security.controller;

import com.znow.admin.system.security.model.res.role.SysRolePageRequest;
import com.znow.admin.system.security.model.res.role.SysRoleRequest;
import com.znow.admin.system.security.model.vo.SysRoleVO;
import com.znow.admin.system.security.service.SysRoleService;
import com.znow.common.model.CommonResult;
import com.znow.common.model.PageResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 系统角色控制器
 *
 * @author Nemo
 * @date 2023/02/02
 */
@RestController
@RequestMapping("/sys/role")
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;

    @ApiOperation(value = "角色列表接口")
    @RequestMapping("/list")
    public CommonResult<PageResult<SysRoleVO>> selectByPage(@RequestBody SysRolePageRequest request) {
        return CommonResult.success(sysRoleService.getRoleList(request));
    }

    @ApiOperation(value = "添加角色接口")
    @PostMapping("/save")
    public CommonResult<Boolean> save(@RequestBody SysRoleRequest request) {
        return CommonResult.success(sysRoleService.saveRole(request));
    }

    @ApiOperation(value = "更新角色接口")
    @PostMapping("/update")
    public CommonResult<Boolean> update(@RequestBody SysRoleRequest request) {
        return CommonResult.success(sysRoleService.updateRole(request));
    }

    @ApiOperation(value = "删除角色接口")
    @PostMapping("/delete")
    public CommonResult<Boolean> delete(@RequestBody SysRoleRequest request) {
        return CommonResult.success(sysRoleService.deleteRole(request));
    }

    @ApiOperation(value = "获取角色详情")
    @RequestMapping("/get")
    public CommonResult<SysRoleVO> get(@RequestBody SysRolePageRequest request) {
        return CommonResult.success(sysRoleService.getRoleDetail(request));
    }

}
